<template>
  <div class="playlists-container">
    <my-scroll ref="listScroll">
      <!-- 同步 -->
      <div class="top-card">
        <div class="icon-wrap">
          <img :src="highQuality.coverImgUrl" alt />
        </div>
        <div class="content-wrap">
          <div class="tag" @click="golist(highQuality.id)">精品歌单</div>
          <div class="title">{{ highQuality.name }}</div>
          <div class="info">{{ highQuality.description }}</div>
        </div>
        <img :src="highQuality.coverImgUrl" alt class="bg" />
        <div class="bg-mask"></div>
      </div>
      <div class="tab-container">
        <!-- tab栏 顶部 -->
        <div class="tab-bar">
          <span
            class="item"
            :class="{ active: tag === '全部' }"
            @click="tag = '全部'"
            >全部</span
          >
          <span
            class="item"
            :class="{ active: tag === '欧美' }"
            @click="tag = '欧美'"
            >欧美</span
          >
          <span
            class="item"
            :class="{ active: tag === '华语' }"
            @click="tag = '华语'"
            >华语</span
          >
          <span
            class="item"
            :class="{ active: tag === '流行' }"
            @click="tag = '流行'"
            >流行</span
          >
          <span
            class="item"
            :class="{ active: tag === '说唱' }"
            @click="tag = '说唱'"
            >说唱</span
          >
          <span
            class="item"
            :class="{ active: tag === '摇滚' }"
            @click="tag = '摇滚'"
            >摇滚</span
          >
          <span
            class="item"
            :class="{ active: tag === '民谣' }"
            @click="tag = '民谣'"
            >民谣</span
          >
          <span
            class="item"
            :class="{ active: tag === '电子' }"
            @click="tag = '电子'"
            >电子</span
          >
          <span
            class="item"
            :class="{ active: tag === '轻音乐' }"
            @click="tag = '轻音乐'"
            >轻音乐</span
          >
          <span
            class="item"
            :class="{ active: tag === '影视原声' }"
            @click="tag = '影视原声'"
            >影视原声</span
          >
          <span
            class="item"
            :class="{ active: tag === 'ACG' }"
            @click="tag = 'ACG'"
            >ACG</span
          >
          <span
            class="item"
            :class="{ active: tag === '怀旧' }"
            @click="tag = '怀旧'"
            >怀旧</span
          >
          <span
            class="item"
            :class="{ active: tag === '治愈' }"
            @click="tag = '治愈'"
            >治愈</span
          >
          <span
            class="item"
            :class="{ active: tag === '旅行' }"
            @click="tag = '旅行'"
            >旅行</span
          >
        </div>
        <!-- tab的内容区域 -->
        <div class="recommended">
          <div class="recombox">
            <div
              class="recom-item"
              v-for="(item, index) in palyLists"
              :key="index"
            >
              <div class="imgbox" @click="golist(item.id)">
                <div class="dsc">
                  <i>播放量：{{ item.subscribedCount | count }}</i>
                </div>
                <img :src="item.coverImgUrl" alt />
              </div>
              <p>{{ item.name }}</p>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <div class="pagebox">
        <el-pagination
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="total"
          :current-page="page"
          :page-size="limit"
        ></el-pagination>
      </div>
      <div class="more" @click="more">
        查看更多
      </div>
    </my-scroll>
  </div>
</template>

<script>
import { GetHightQuality, GetList } from "../../api/music"
export default {
  name: "recommend",
  data() {
    return {
      highQuality: {},
      tag: "全部",
      palyLists: [],
      // 总条数
      total: 0,
      limit: 12,
      // 页码
      page: 1,
    }
  },
  created() {
    this.gethightquality()
    this.getList()
  },
  filters: {
    count(playcount) {
      if (playcount > 10000) {
        playcount = Math.ceil(playcount / 10000) + "万"
      }
      return playcount
    },
  },
  watch: {
    tag(newVal, oldVal) {
      this.page = 1
      this.tag = newVal
      this.gethightquality()
      this.getList()
    },
  },
  methods: {
    golist(id) {
      this.$router.push(`/musichome/listinfo?id=${id}`)
    },
    handleCurrentChange(val) {
      this.page = val
      this.getList()
      this.$refs["listScroll"].$refs["vs"].scrollTo(
        {
          y: "0%",
        },
        0
      )
    },
    async gethightquality() {
      const res = await GetHightQuality({
        cat: this.tag,
      })
      this.highQuality = res.playlists[0]
    },
    async getList() {
      const res = await GetList({
        offset: (this.page - 1) * this.limit,
        cat: this.tag,
        limit: 12,
      })
      this.palyLists = res.playlists
      this.total = res.total
    },
    // 移动端加载更多
    async more() {
      const res = await GetList({
        offset: (this.page - 1) * this.limit,
        cat: this.tag,
        limit: 12,
      })
      this.palyLists.push(...res.playlists)
      this.total = res.total
    },
  },
}
</script>

<style lang="scss" scoped>
@media (max-width: 600px) {
  .playlists-container {
    width: 100%;
    height: 100%;
  }
  .playlists-container .top-card {
    margin: 0.625rem;
    padding: 0.625rem;
    display: flex;
    position: relative;
    overflow: hidden;
    border-radius: 5px;
  }

  .playlists-container .top-card .icon-wrap {
    margin-right: 20px;
    z-index: 1;
    display: none;
  }
  .playlists-container .top-card .content-wrap {
    z-index: 1;
  }

  .playlists-container .top-card .content-wrap .tag {
    color: #dfac67;
    border: 1px solid #dfac67;
    width: 100px;
    height: 30px;
    text-align: center;
    border-radius: 5px;
    font-size: 16px;
    line-height: 30px;
    cursor: pointer;
  }

  .playlists-container .top-card .content-wrap .title {
    color: white;
    padding-top: 10px;
  }

  .playlists-container .top-card .content-wrap .info {
    color: #888482;
    line-height: 20px;
    font-size: 14px;
    padding-top: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
  }

  .playlists-container .top-card .bg {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    filter: blur(20px);
  }

  .playlists-container .top-card .bg-mask {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
  }

  .playlists-container .tab-container {
    margin: 0rem 0.625rem;
  }

  .playlists-container .tab-container .tab-bar {
    display: flex;
    flex-wrap: wrap;
  }

  .playlists-container .tab-container .tab-bar .item {
    font-size: 0.875rem;
    color: gray;
    padding: 0rem 0.25rem;
    line-height: 1.25rem;
    cursor: pointer;
  }

  .playlists-container .tab-container .tab-bar .item.active {
    color: rgb(98, 158, 218);
  }
  .recombox {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    :after {
      content: "";
      width: 180px;
    }
  }
  .recom-item {
    box-sizing: border-box;
    width: 50%;
    padding: 0px 10px;
    margin-top: 0.625rem;
    box-sizing: border-box;
    .imgbox {
      width: 100%;
      border-radius: 0.3125rem;
      position: relative;
      overflow: hidden;
      img {
        width: 100%;
        border-radius: 0.3125rem;
      }
      .dsc {
        position: absolute;
        width: 100%;
        height: 30px;
        background-color: rgba(0, 0, 0, 0.5);
        top: 0px;
        left: 0px;
        transition: 0.5s;
        text-align: right;
        i {
          display: inline-block;
          width: 85%;
          color: rgb(255, 255, 255);
          font-size: 14px;
          line-height: 25px;
          font-style: normal;
          margin: 0px 10px;
        }
      }
    }
    .imgbox:hover {
      cursor: pointer;
    }
    .imgbox:hover .dsc {
      top: 0px;
    }
    p {
      margin: 0px;
      height: 30px;
      line-height: 30px;
      font-size: 13px;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .pagebox {
    display: none;
  }
  .more {
    width: 100%;
    text-align: center;
    display: block;
    line-height: 1rem;
    padding: 0.9rem 0rem;
    color: rgba(168, 168, 168, 0.8);
  }
}
@media (min-width: 600px) {
  .playlists-container {
    width: 100%;
    height: 100%;
  }
  .playlists-container .top-card {
    margin: 20px 20px;
    padding: 20px;
    display: flex;
    position: relative;
    overflow: hidden;
    border-radius: 5px;
  }

  .playlists-container .top-card .icon-wrap {
    margin-right: 20px;
    z-index: 1;
  }

  .playlists-container .top-card .icon-wrap img {
    width: 160px;
    height: 160px;
  }

  .playlists-container .top-card .content-wrap {
    z-index: 1;
  }

  .playlists-container .top-card .content-wrap .tag {
    color: #dfac67;
    border: 1px solid #dfac67;
    width: 100px;
    height: 30px;
    text-align: center;
    border-radius: 5px;
    font-size: 16px;
    line-height: 30px;
    cursor: pointer;
  }

  .playlists-container .top-card .content-wrap .title {
    color: white;
    padding-top: 10px;
  }

  .playlists-container .top-card .content-wrap .info {
    color: #888482;
    line-height: 20px;
    font-size: 14px;
    padding-top: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
  }

  .playlists-container .top-card .bg {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    filter: blur(20px);
  }

  .playlists-container .top-card .bg-mask {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
  }

  .playlists-container .tab-container {
    padding-top: 30px;
    margin: 0px 20px;
  }

  .playlists-container .tab-container .tab-bar {
    display: flex;
    justify-content: flex-end;
  }

  .playlists-container .tab-container .tab-bar .item {
    font-size: 14px;
    color: gray;
    margin-right: 10px;
    cursor: pointer;
  }

  .playlists-container .tab-container .tab-bar .item.active {
    color: rgb(98, 158, 218);
  }
  .recombox {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    :after {
      content: "";
      width: 180px;
    }
  }
  .recom-item {
    box-sizing: border-box;
    width: 200px;
    padding: 0px 10px;
    height: 210px;
    margin: 20px 0px;
    .imgbox {
      width: 180px;
      height: 180px;
      background: rgb(59, 144, 214);
      border-radius: 5px;
      position: relative;
      overflow: hidden;
      img {
        width: 180px;
      }
      .dsc {
        position: absolute;
        width: 100%;
        height: 30px;
        background-color: rgba(0, 0, 0, 0.5);
        top: 0px;
        left: 0px;
        transition: 0.5s;
        text-align: right;
        i {
          display: inline-block;
          width: 85%;
          color: rgb(255, 255, 255);
          font-size: 14px;
          line-height: 25px;
          font-style: normal;
          margin: 0px 10px;
        }
      }
    }
    .imgbox:hover {
      cursor: pointer;
    }
    .imgbox:hover .dsc {
      top: 0px;
    }
    p {
      margin: 0px;
      height: 30px;
      line-height: 30px;
      font-size: 13px;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .pagebox {
    display: flex;
    width: 100%;
    height: 60px;
    justify-content: center;
    align-items: center;
  }
  .more {
    display: none;
  }
}
</style>
